﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyKTVService;
using MyKTVUtils;


namespace MyKTV02
{
    public partial class frmSingerShow : Form
    {
        public frmSingerShow()
        {
            InitializeComponent();
        }
        SingerService Sservice = new SingerService();
        private void frmSingerShow_Load(object sender, EventArgs e)
        {
            
            cboSingerType.DataSource = Sservice.BindCboData();
            cboSingerType.DisplayMember= "singertype_name";
            cboSingerType.ValueMember = "singertype_id";
            this.dgvSingerList.DataSource = Sservice.SelectSinger(null, 0, pageIndex, pageSize, ref totalCount);
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            string name = this.txtSingerName.Text;
            int TypeId =Convert.ToInt32( cboSingerType.SelectedValue);
            this.dgvSingerList.DataSource = Sservice.SelectSinger(name, TypeId, pageIndex, pageSize, ref totalCount);
             pageIndex = 1;
        }
        /// <summary>
        /// 分页 每页显示3条数据
        /// </summary>
        int pageSize = 3;

        /// <summary>
        /// 当前第几页 默认从第一页开始
        /// </summary>
        int pageIndex = 1;
        /// <summary>
        /// 符合查询条件的总记录数
        /// </summary>
        int totalCount = 0;

        /// <summary>
        /// 总页数
        /// </summary>
        int totalPage = 0;
        private void btnLeft_Click(object sender, EventArgs e)
        {
            if (pageIndex>1)
            {
                pageIndex--;
                string name = this.txtSingerName.Text;
                int TypeId = Convert.ToInt32(cboSingerType.SelectedValue);
                this.dgvSingerList.DataSource = Sservice.SelectSinger(name, TypeId, pageIndex, pageSize, ref totalCount);
            }
            else {
                MessageBox.Show("第一页了");

            }
        }
        
        private void btnRight_Click(object sender, EventArgs e)
        {
            if ((totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1) > pageIndex)
            {
                pageIndex++;
                string name = this.txtSingerName.Text;
                int TypeId = Convert.ToInt32(cboSingerType.SelectedValue);
                this.dgvSingerList.DataSource = Sservice.SelectSinger(name, TypeId, pageIndex, pageSize, ref totalCount);
            }
            else
            {
                MessageBox.Show("最后一页了");

            }
        }
    }
}
